JavaScript

A5.u.arraymove Method

Syntax

A5.u.array.move(array,indexes,location)

Arguments

arrayarray

The array to move items in.

indexesnumberarrayobject

The array of index(es) to move.

startnumber

When selecting a range of items, the index to start on.

endnumber

When selecting a range of items, the index to end on. Either the end or length must be specified.

lengthnumber

When selecting a range of items, the number of items to move. Either the end or length must be specified.

locationnumberstring

The location to move the array items to. Can be the index to move them to, or a string with relative movement commands.

Returns

movedboolean

Whether or not items were moved.

Description

Move the items with the given indexes in the array.

Discussion

The A5.u.array.move method moves items in an array. The indexes can either be specified as a single number, and array of numbers, or an object that specifies the start index and either end index or length. None contiguous indexes will be clustered into a single continuos group before the move occurs.

The location to move the items to can be specified as either an index, or a relative command. A string of "start" or "top" will move the items to the beginning of the array, while "end" or "bottom" will move the items to the end of the array. A string of "up" or "back" will decrease the item indexes relative to the first item, while "down" or "forward" will move increase the item indexes relative to the last item. These relative movements can be adjusted by adding a numeric suffix, for example "down+2" will move the selected indexes 3 down from the last item.

Example

var a = ['a','b','c','d','e','f','g','h','i'];
A5.u.array.move(a,[3,5],6);
// a = ['a','b','c','e','g','h','d','f','i']
A5.u.array.move(a,2,'up');
// a = ['a','c','b','e','g','h','d','f','i']